home *** CD-ROM | disk | FTP | other *** search
- Path: fc.hp.com!news
- From: Rick Wells <rwells@blkbear.fc.hp.com>
- Newsgroups: comp.lang.c
- Subject: Re: [Help] I can't find my error.
- Date: Fri, 23 Feb 1996 09:58:41 -0700
- Organization: Hewlett-Packard Fort Collins Site
- Message-ID: <312DF241.23CC@blkbear.fc.hp.com>
- References: <4ggvgr$1b2@aurora.engr.LaTech.edu> <4givk5$bqk@aphex.direct.ca>
- NNTP-Posting-Host: blkbear.fc.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.07 9000/715)
-
- Ed Toivanen wrote:
- >
- >
- > #include <stdio.h>
- > #include <stdlib.h>
- >
- > #define NAMESIZE 100
- > #define BUFSIZE 4
- >
- > int main(void)
- > {
- > char buf[BUFSIZE];
- > char name[NAMESIZE];
- > int age, next_age;
- >
- > printf("Please enter your name:\t");
- > name = fgets(buf, sizeof(buf), stdin);
- > printf("\nPlease enter your age:\t");
- > age = atoi(fgets(buf, sizeof(buf), stdin));
- > next_age += age;
- > printf("\nHi, %s ,next year, you will be %d\n", name, next_age);
- >
- > return(0);
- > }
- >
- The error I get when I compile this is as follows:
-
- cc: "test.c", line 14: error 1549: Modifiable lvalue required for
- assignment operator.
-
- This would make sense. It's complaining about the assignment of the
- result of
- fgets to your variable "name". Name is an array of size NAMESIZE. What
- fgets
- returns is a pointer to buf. You can't assign a new address to name
- because
- then you'd lose access to the space that was orginally allocated for
- name.
- I suggest you replace that line with the following:
-
- fgets(name, sizeof(name), stdin);
-
- Rick
-